package com.heima.controller;

import com.heima.common.PageResult;
import com.heima.pojo.dto.ManageCommodityDTO;
import com.heima.pojo.dto.SkuClassSearchDto;
import com.heima.pojo.vo.SkuSearchVO;
import com.heima.service.ManageCommodityservice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/vm-service/sku")
@Api(tags = "商品管理接口")
public class ManageCommodityController {

    @Autowired
    ManageCommodityservice manageCommodityservice;

    /**
     * 新增商品
     **/
    @ApiOperation("新增商品")
    @PostMapping
    private Boolean add(@RequestBody ManageCommodityDTO dto) {
        manageCommodityservice.add(dto);
        return true;
    }

    /**
     * 分页查询
     **/
    @ApiOperation("分页查询")
    @GetMapping("/search")
    public PageResult<SkuSearchVO> searchVo(SkuClassSearchDto dto) {
        PageResult<SkuSearchVO> result = manageCommodityservice.pagingQuery(dto);
        return result;
    }
   /**
    * 修改商品
    * **/
   @ApiOperation("修改商品")
    @PutMapping("{skuId}")
    public Boolean  upd (@PathVariable("skuId") Integer skuId, @RequestBody ManageCommodityDTO dto){
       manageCommodityservice.upd(skuId,dto);
       return true;
   }
}
